//package com.ydkfjs.controller;
//
//import com.alibaba.fastjson2.JSONArray;
//import com.alibaba.fastjson2.JSONObject;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.http.*;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.client.RestTemplate;
//
//import java.util.Collections;
//
///**
// * @Author: hb
// * @CreateTime: 2024-02-21 22:26
// * @Version: 1.0
// */
//@Slf4j
//@RestController
//@RequestMapping("/test")
//public class TestController {
//
////    @GetMapping
////    public String test1(){
////        return "Hello World!";
////    }
//
//    @GetMapping
//    public String sendPost(String data) {
//        RestTemplate client = new RestTemplate();
//        HttpHeaders httpHeaders = new HttpHeaders();
//        httpHeaders.add("Authorization","Bearer sk-proj-uDQkL187OVwdrniVWVC5T3BlbkFJfxDBQ12NH4jmJv8xyAz3");
//        httpHeaders.add("Content-Type", "application/json"); // 传递请求体时必须设置
////        String requestJson = "{\n" +
////                "    \"model\": \"text-davinci-003\",\n" +
////                "     \"prompt\": \"你好\",\n" +
////                "      \"temperature\": 0, \n" +
////                "      \"max_tokens\": 2048\n" +
////                "}";
//        String requestJson = String.format(
//                "{\n" +
//                        "    \"model\": \"text-embedding-3-small\",\n" +
//                        "     \"prompt\": \"%s\",\n" +
//                        "      \"temperature\": 0, \n" +
//                        "      \"max_tokens\": 2048\n" +
//                        "}",data
//        );
//        HttpEntity<String> entity = new HttpEntity<String>(requestJson,httpHeaders);
//        ResponseEntity<String> response = client.exchange("https://api.openai.com/v1/embeddings", HttpMethod.POST, entity, String.class);
//        System.out.println(response.getBody());
//        JSONObject jsonObject = JSONObject.parseObject(response.getBody());
//        JSONArray choices = jsonObject.getJSONArray("choices");
//        String text = choices.getJSONObject(0).getString("text");
////        Object o = jsonObject.get("\"choices\"");
//        return text;
//    }
//
//
////    @PostMapping("/chat")
////    public ResponseEntity<String> chat(@RequestBody String message) {
////        RestTemplate restTemplate = new RestTemplate();
////        // OpenAI URL
////        String url = "https://api.openai.com/v1/engines/davinci-codex/completions";
////        // 将“YOUR-API-KEY”替换为您的OpenAI密钥
////        String apiKey = "Bearer sk-proj-uDQkL187OVwdrniVWVC5T3BlbkFJfxDBQ12NH4jmJv8xyAz3";
////        // 创建HTTP请求头
////        HttpHeaders headers = new HttpHeaders();
////        headers.setContentType(MediaType.APPLICATION_JSON);
////        headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
////        headers.set("Authorization", apiKey);
////        // 创建一个聊天模型实例
////        ChatModel chatModel = new ChatModel();
////        chatModel.setPrompt(message);
////        chatModel.setMaxTokens(100);
////
////        // 发送POST请求
////        HttpEntity<ChatModel> entity = new HttpEntity<>(chatModel, headers);
////        ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
////        // 返回响应实体
////        return response;
////    }
////    public static void main(String[] args) {
////        String ssl = sendPost("你好");
////        System.out.println(ssl);
////    }
//}
